package gui.popup;

/*
 * This class checks of there is an error in the input data of a popup. You can use it by calling function. 
 * Once you create a pareError there is no error. If one or more of the test fail you get an error at the end.
 */

public class ParseError {
	private boolean obligatedFields = false;
	private boolean fieldLengths = false;
	private boolean fieldTypes = false;
	
	/**
	 * if an field is obligated you can call this function. the obligatedFields error turns true when an empty string or null is given.
	 * @param field String obligated input field
	 */
	public void obligatedField(String field) {
		if(field == null) {
			obligatedFields = true;
		}
		else if(field.length() == 0) {
			obligatedFields = true;
		}
	}
	
	/**
	 * You can use this function to determine if the maximum length is reached
	 * @param field String obligated input field
	 */
	public void fieldLength(String field, int maxLength) {
		if(field.length()>maxLength) {
			fieldLengths = true;
		}		
	}
	
	/**
	 * this function needs to be in an try catch algoritm. when an parseException reveals this function can set the fieldTypes flag true.
	 */
	public void parseError() {
		fieldTypes = true;
	}
	
	/**
	 * this function returns true if there where error found.
	 * 
	 * @return boolean when <code>true</code> there where errors found
	 */
	public boolean errorsPresent() {
		return obligatedFields || fieldLengths || fieldTypes;
	}
	
	/**
	 * parses errors to errorStrings for the user.
	 * @return errorStrings
	 */
	public String getErrorString() {
		String explain = "";
		if(obligatedFields) {
			explain += "Er zijn 1 of meer verplichte velden niet ingevoerd!\n";
		}
		if(fieldLengths) {
			explain += "Er zijn 1 of meer velden te lang!\n";
		}
		if(fieldTypes) {
			explain += "Er zijn 1 of meer veldTypes verkeerd ingevoerd!\n";
		}
		return explain;
	}
	
}
